
var express = require('express')
var router = express.Router()
var ueditor = require('ueditor')
var path = require('path')

var configFile = 'config.'+process.env.NODE_ENV+'.json'
var config = require('../../config/'+configFile);

router.get("/", function(req, res, next) {
  return res.send("hello")
})

router.use("/ue", ueditor(path.join(__dirname, 'public'), function(req, res, next){
  // ueditor 客户发起上传图片请求
    if (req.query.action === 'uploadimage') {
        var foo = req.ueditor;

        var imgname = req.ueditor.filename;

        var img_url = '../../public/ueditor/images/' ;
        res.ue_up(img_url); //你只要输入要保存的地址 。保存操作交给ueditor来做
    }
    //  客户端发起图片列表请求
    else if (req.query.action === 'listimage') {
        var dir_url = '/public/ueditor/images/';
        res.ue_list(dir_url); // 客户端会列出 dir_url 目录下的所有图片
    }
    // 客户端发起其它请求
    else {
        // console.log('config.json')
        res.setHeader('Content-Type', 'application/json');
        res.redirect('/public/ueditor/nodejs/config.json');
    }
}))


module.exports = router;
